package com.supermap.localization.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.oro.text.regex.MalformedPatternException;

public class MatcherUtil {

    public static String exclude(String src, String regex) throws MalformedPatternException {
        Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
        Matcher matcher = pattern.matcher(src);
        src = matcher.replaceAll("");
        return src;
    }

    public static List<String> include(String src, String regex) throws MalformedPatternException {
        List<String> result = new ArrayList<>();
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(src);
        while (matcher.find()) {
            result.add(matcher.group());
        }
        return result;
    }

    public static boolean contains(String src, String regex) throws MalformedPatternException {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(src);
        return matcher.find();
    }
}
